<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script>
            const arr = [9, 1, 3, 2, 8, 0, 5, 7, 6, 4]
            const arr2 = [9, 8, 7, 6, 5, 4, 3, 2, 1]

            function sort(array) {
                const arr = [...array]
                for (let i = 0; i < arr.length; i++) {
                    for (let j = i + 1; j < arr.length; j++) {
                        if (arr[i] > arr[j]) {
                            // 交换两个元素的位置
                            let temp = arr[i]
                            arr[i] = arr[j]
                            arr[j] = temp
                        }
                    }
                }
                return arr
            }

            let result = sort(arr2)

            // console.log(arr2)
            // console.log(result)

            class Person {
                constructor(name, age) {
                    this.name = name
                    this.age = age
                }
            }

            const personArr = [
                new Person("孙悟空", 18),
                new Person("沙和尚", 38),
                new Person("红孩儿", 8),
                new Person("白骨精", 16),
            ]


            // filter()函数用来对数组进行过滤
            function filter(arr) {

                const newArr = []

                for (let i = 0; i < arr.length; i++) {
                    if (arr[i].age < 18) {
                        newArr.push(arr[i])
                    }
                }

                return newArr
            }

            result = filter(personArr)
            console.log(result)
        </script>
    </head>
    <body></body>
</html>
